﻿if exists (select * from sysobjects where id = object_id(N'pBUGLOGBugsSummaryGet') and sysstat & 0xf = 4) drop procedure pBUGLOGBugsSummaryGet 
GO

-- Returns a specific record from the [dbo].[BugsSummary] table.
CREATE PROCEDURE pBUGLOGBugsSummaryGet
        @pk_BugId int
AS
DECLARE
    @l_count int
BEGIN

    -- Get the rowcount first and make sure 
    -- only one row is returned
    SELECT @l_count = count(*) 
    FROM [dbo].[BugsSummary]
    WHERE [BugId] =@pk_BugId

    IF @l_count = 0
        RAISERROR ('The record no longer exists.', 16, 1)
    IF @l_count > 1
        RAISERROR ('duplicate object instances.', 16, 1)

    -- Get the row from the query.  Checksum value will be
    -- returned along the row data to support concurrency.
    SELECT 
        [BugId],
        [BugShortDescription],
        [Date],
        [userID],
        [PriorityID],
        [StatusID],
        [Assigned],
        [FixedBy],
        [Description],
        [EnvBUGLOGment],
        [StepsToReproduce],
        [Note],
        [ImageAttachment],
        [TaskID],
        [TestCaseID],
        CAST(BINARY_CHECKSUM([BugId],[BugShortDescription],[Date],[userID],[PriorityID],[StatusID],[Assigned],[FixedBy],[Description],[EnvBUGLOGment],[StepsToReproduce],[Note],[ImageAttachment],[TaskID],[TestCaseID]) AS nvarchar(4000)) AS IS_CHECKSUM_COLUMN_12345
    FROM [dbo].[BugsSummary]
    WHERE [BugId] =@pk_BugId
END

